#ifndef __MATH_EXT__
#define __MATH_EXT__

#include <math.h>
#include <cstddef>

namespace math_ext
{
template <long num, size_t n, size_t y = 1>
struct pow
{
    enum { value = pow<num * num, (n >> 1), n & 1 ? num * y : y>::value };
};
template <long num, size_t y>
struct pow<num, 0, y>
{
    enum { value = y };
};
// round
#if __cplusplus > 199711L
template <size_t Precision, typename typeFloat = double>
#else
template <size_t Precision, typename typeFloat>
#endif
inline typeFloat round(typeFloat x)
{
    enum
    {
        PrecMul = math_ext::pow<10, Precision>::value
    };
    return (x > 0. ? floor(x * PrecMul + 0.5) : ceil(x * PrecMul - 0.5)) / PrecMul;
}



#if __cplusplus > 199711L
template <typename typeFloat = double>
#else
template <typename typeFloat>
#endif
typeFloat round (typeFloat x, int precision)
{
   long mul = 1;

   for (int i = 0; i < precision; i++)
      mul *= 10;
   if (x > 0)
      return floor(x * mul + .5) / mul;
   else
      return ceil(x * mul - .5) / mul;
}

} //math_ext




#endif
